package java_0629;

public class ThreadDemo7 {
     static final long count = 100_0000_0000l;
     public static void serial(){
         long begin = System.currentTimeMillis();
         long a = 0;
         while(a<count){
             a++;
         }
         long b = 0;
         while(b<count){
             b++;
         }
         long end = System.currentTimeMillis();
         System.out.println(end-begin);
     }

     public static void concurrency(){
         long begin = System.currentTimeMillis();
         Thread thread1 = new Thread(){
             @Override
             public void run() {
                 long a = 0;
                 while(a<count){
                     a++;
                 }
             }
         };
         thread1.start();
         Thread thread2 = new Thread(){
             @Override
             public void run() {
                 long b = 0;
                 while(b<count){
                     b++;
                 }
             }
         };
         thread2.start();
         try {
             thread1.join();
             thread2.join();
         } catch (InterruptedException e) {
             e.printStackTrace();
         }

         long end = System.currentTimeMillis();
         System.out.println(end-begin);
     }

    public static void main(String[] args) {
       serial();
       concurrency();
    }
}
